<template>
  <view class="test-feedback-container">
    <view class="header">
      <text class="title">反馈功能测试</text>
    </view>

    <view class="test-section">
      <view class="section-title">API测试</view>
      
      <button class="test-btn" @click="testGetAdminNames">测试获取管理员列表</button>
      <button class="test-btn" @click="testGetFeedbackList">测试获取反馈列表</button>
      <button class="test-btn" @click="testAddFeedback">测试添加反馈</button>
    </view>

    <view class="result-section">
      <view class="section-title">测试结果</view>
      <view class="result-content">
        <text>{{ testResult }}</text>
      </view>
    </view>
  </view>
</template>

<script>
import { ref } from 'vue'
import request from '@/utils/request.js'
import tokenManager from '@/utils/token.js'

export default {
  name: 'TestFeedback',
  setup() {
    const testResult = ref('点击上方按钮开始测试...')

    // 测试获取管理员列表
    const testGetAdminNames = async () => {
      testResult.value = '正在测试获取管理员列表...'
      
      try {
        const response = await request.request({
          url: '/feedback/admin-names',
          method: 'GET'
        })
        
        testResult.value = `获取管理员列表结果：\n${JSON.stringify(response, null, 2)}`
      } catch (error) {
        testResult.value = `获取管理员列表错误：\n${error.message}`
      }
    }

    // 测试获取反馈列表
    const testGetFeedbackList = async () => {
      if (!tokenManager.isLoggedIn()) {
        testResult.value = '请先登录后再测试'
        return
      }

      testResult.value = '正在测试获取反馈列表...'
      
      try {
        const response = await request.request({
          url: '/feedback/list',
          method: 'GET'
        })
        
        testResult.value = `获取反馈列表结果：\n${JSON.stringify(response, null, 2)}`
      } catch (error) {
        testResult.value = `获取反馈列表错误：\n${error.message}`
      }
    }

    // 测试添加反馈
    const testAddFeedback = async () => {
      if (!tokenManager.isLoggedIn()) {
        testResult.value = '请先登录后再测试'
        return
      }

      testResult.value = '正在测试添加反馈...'
      
      try {
        const params = {
          content: '这是一条测试反馈，用于验证反馈功能是否正常工作。',
          adminId: 1,
          adminRealName: '测试管理员',
          images: ''
        }

        const response = await request.request({
          url: '/feedback/add',
          method: 'POST',
          data: params
        })
        
        testResult.value = `添加反馈结果：\n${JSON.stringify(response, null, 2)}`
      } catch (error) {
        testResult.value = `添加反馈错误：\n${error.message}`
      }
    }

    return {
      testResult,
      testGetAdminNames,
      testGetFeedbackList,
      testAddFeedback
    }
  }
}
</script>

<style scoped>
.test-feedback-container {
  min-height: 100vh;
  background-color: #f5f5f5;
  padding: 20rpx;
}

.header {
  text-align: center;
  margin-bottom: 30rpx;
}

.title {
  font-size: 36rpx;
  font-weight: bold;
  color: #333;
}

.test-section, .result-section {
  background-color: white;
  border-radius: 12rpx;
  padding: 30rpx;
  margin-bottom: 20rpx;
}

.section-title {
  font-size: 28rpx;
  font-weight: bold;
  color: #333;
  margin-bottom: 20rpx;
}

.test-btn {
  width: 100%;
  height: 80rpx;
  background: linear-gradient(135deg, #4CAF50 0%, #45a049 100%);
  color: white;
  border: none;
  border-radius: 12rpx;
  font-size: 26rpx;
  margin-bottom: 20rpx;
}

.result-content {
  background-color: #f8f9fa;
  border-radius: 8rpx;
  padding: 20rpx;
  min-height: 200rpx;
}

.result-content text {
  font-size: 24rpx;
  color: #333;
  line-height: 1.5;
  white-space: pre-wrap;
}
</style>


